/*
 * =====================================================================================
 *
 *       Filename:  pipe1.c
 *
 *    Description:  demo of how pipe works
 *
 *        Version:  1.0
 *        Created:  05/04/2012 01:30:34 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Zhiyi Wu (Z.W), zhiyiw@uoregon.edu
 *        Company:  University of Oregon
 *
 * =====================================================================================
 */

#include <stdio.h>  
#include <unistd.h>  
#include <string.h>  
#include	<wait.h>
#define MAX_LINE 80  
#define PIPE_STDIN 0  
#define PIPE_STDOUT 1  




int main(  )  
{  
	int ret,thePipe[2]; 
	char buf[MAX_LINE+1];  
	const char* testbuf={"Hello--- from pipe."};  
	ret=pipe(thePipe);   //pipe() create a pipe  
	if(ret==0)  
	{ 
		write(thePipe[PIPE_STDOUT],testbuf,strlen(testbuf));  
		ret=read(thePipe[PIPE_STDIN],buf,MAX_LINE );  
		buf[ret]=0;  
		printf( "%s\n",buf );  
	//	printf("%d\n",thePipe[PIPE_STDOUT]);


	}  
	close( thePipe[ 0 ] );  
	close( thePipe[ 1 ] );  

	return 0;  
}  
